home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / bnews093.zip / bnewsfilter.cmd < prev    next >
OS/2 REXX Batch file  |  1996-10-31  |  6KB  |  168 lines

  1. /*  bnewsfilter.cmd
  2.  *
  3.  *  Filter for bnews.
  4.  *
  5.  *  bnews /cover | bnewsfilter | bnews /cart > art.uue
  6.  *  bnews /cover | bnewsfilter | bnews /cart | uudeview -i -
  7.  *  type <group>.get.txt | bnews /cart | uudeview -io -
  8.  *
  9.  */
  10.  
  11.   MIN_BODY_LINES = 100          /* Trash articles with less than this       */
  12.                                 /* number of lines in the message body      */
  13.                                 /* to help eliminate discussion and         */
  14.                                 /* keep only binary articles.               */
  15.  
  16.   drop keep.                    /* Stem variable of articles to keep.       */
  17.   drop trash.                   /* "                "        to trash.      */
  18.  
  19.                                 /* keep.0 and trash.0 are the total         */
  20.                                 /* number of items in the stem variables    */
  21.  
  22.   keep.0    = 6                 /* Number of items in stem variable keep.   */
  23.   keep.1    = ".AVI"            /* keep.1 to keep.x are strings to keep     */
  24.   keep.2    = ".MPG"            /* must be UPPER CASE                       */
  25.   keep.3    = ".MOV"
  26.   keep.4    = ".ZIP"
  27.   keep.5    = ".JPG"
  28.   keep.6    = ".GIF"
  29.  
  30.   trash.0   = 17                /* Number of items in stem variable trash.  */
  31.   trash.1   = "CASH"            /* trash.1 to trash.x are strings to trash  */
  32.   trash.2   = "*** DOT"         /* must be UPPER CASE                       */
  33.   trash.3   = ".WAV"
  34.   trash.4   = "BONDAGE"
  35.   trash.5   = "CLINTON"
  36.   trash.6   = "FREE"
  37.   trash.7   = "GAY"
  38.   trash.8   = "HOT TEEN"
  39.   trash.9   = "NIGGER"
  40.   trash.10  = "SCREENSAVER"
  41.   trash.11  = "SITE"
  42.   trash.12  = "SPAM"
  43.   trash.13  = "STRIP POKER"
  44.   trash.14  = "UPSKIRT"
  45.   trash.15  = "HOT MEN"
  46.   trash.16  = "MCARTH"
  47.   trash.17  = "STUD"
  48.  
  49.  
  50.   signal on Halt
  51.   signal on NoValue
  52.  '@echo off'
  53.   parse arg arg0
  54.  
  55.   drop oline.                       /* overview line after parsing          */
  56.   iread = 0                         /* count of total lines read            */
  57.   isave = 0                         /* count of total lines saved           */
  58.   line0 = ""                        /* line read from stdin                 */
  59.   line  = ""                        /* line used for comparison upper case  */
  60.  
  61.   call SysCurState 'Off'
  62.   do forever                        /* main loop */
  63.     line0 = linein()                /* preserve case in line0 */
  64.     iread = iread + 1
  65.     if lines() == 0 then leave
  66.     if pos("Elapsed time:", line0) > 0
  67.       then leave
  68.     line = translate(line0)         /* to upper case for comparison */
  69.     oline.0 = ParseLine(line0)
  70.  
  71.     /*  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  */
  72.     /*  After ParseLine, oline contains the following if oline.0 > 1         */
  73.     /*  oline.1   article number                                             */
  74.     /*  oline.2   subject                                                    */
  75.     /*  oline.3   from                                                       */
  76.     /*  oline.4   date/time                                                  */
  77.     /*  oline.5   reply to?                                                  */
  78.     /*  oline.6   msg id?                                                    */
  79.     /*  oline.7   number of bytes in body of message                         */
  80.     /*  oline.8   number of lines in body of message                         */
  81.     /*  oline.9   xref:                                                      */
  82.     /*  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  */
  83.  
  84.     if oline.0 > 1 then do
  85.       if oline.8 > MIN_BODY_LINES then do
  86.         linecmp = translate(oline.2)
  87.         do i = 1 to keep.0
  88.           /* look at subject for things to keep */
  89.           if pos(keep.i, linecmp) > 0 then do
  90.             /* look for trash in the subject */
  91.             do j = 1 to trash.0
  92.               /* found trash, leave */
  93.               if pos(trash.j, linecmp) > 0 then do
  94.                 i = keep.0
  95.                 leave
  96.               end
  97.               /* no trash, keep line */
  98.               else do
  99.                 say line0
  100.                 isave = isave + 1
  101.                 /* show some progress */
  102.                /*call SysCls
  103.                  call lineout 'stderr', 'Lines read:' iread' Lines saved:' isave
  104.                 */
  105.                 i = keep.0
  106.                 leave
  107.               end
  108.             end
  109.           end
  110.         end
  111.       end
  112.     end
  113.     /* couldn't parse tabs, save line just incase */
  114.     else do
  115.       say line0
  116.     end
  117.   end
  118.   return 0
  119.  /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  120.  /*                              End of main                            */
  121.  /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  122.  
  123.  /*
  124.   * ParseLine - tokenize line by tabs - 09H
  125.   *
  126.   * results are in the stem variable oline.1 to oline.x
  127.   * oline.0 contains total number of items.
  128.   *
  129.   */
  130.  
  131.   ParseLine:
  132.     parse arg line
  133.     tabcnt = 1
  134.     tabpos = 1
  135.     tabposlast = 1
  136.  
  137.     do forever
  138.       tabpos = pos('09'x, line, tabpos)
  139.       if tabpos == 0 then leave
  140. /*    say 'tabcnt='tabcnt' tabpos='tabpos' tabposlast='tabposlast*/
  141.       oline.tabcnt = substr(line, tabposlast + 1, tabpos - tabposlast - 1)
  142.       tabcnt = tabcnt + 1
  143.       tabposlast = tabpos;
  144.       tabpos = tabpos + 1
  145.     end
  146.     oline.tabcnt = substr(line, tabposlast + 1)
  147.     oline.0 = tabcnt
  148.     return oline.0
  149.  
  150.  
  151.  /*
  152.   * Ctrl- Break catcher
  153.   */
  154.  
  155.   Halt:
  156.     call SysCurState 'On'
  157.     say 'ouch... line 'sigl
  158.     exit 1
  159.  
  160.  
  161.  /*
  162.   * Initialization error handler
  163.   */
  164.  
  165.   NoValue:
  166.     say 'no value at line 'sigl
  167.     exit 1
  168.